<?php

use Illuminate\Database\Seeder;
use Spatie\Permission\Models\Role;
class AdminSeeder extends Seeder
{
    /**
     * Run the database seeds.w
     *
     * @return void
     */
    public function run()
    {
        factory(\App\Admin::class,10)->create();
        $user = \App\Admin::find(1);
        $user->name = 'admin';
        $user->nickname = '管理员';
        $user->is_admin = 1;
        $user->save();
        $user2 = \App\Admin::find(2);
        $user2->name = 'lier';
        $user2->nickname = '李二';
        $user2->save();
        $user3 = \App\Admin::find(3);
        $user3->name = 'lisan';
        $user3->nickname = '李三';
        $user3->save();




        //临时用数据填充的方式添加一个角色名称
        Role::create([
           'name' => 'admin',
           'title' => '超级管理员',
            'guard_name' => 'admin'
        ]);
        Role::create([
            'name' => 'master',
            'title' => '经理',
            'guard_name' => 'admin'
        ]);
        Role::create([
           'name' => 'banzhu',
            'title' => '版主',
            'guard_name' => 'admin'
        ]);

        //使用assignRole()方法给某个用户添加一个角色，直接传递角色的英文标识，如果要添加多个角色，用数组的形式进行传递
        $user->assignRole('admin');
        $user2->assignRole('master');
        $user3->assignRole('banzhu');
    }
}
